package org.darkforest.common.services.impl;

import org.darkforest.common.services.EmployeeService;
import org.darkforest.common.util.DateUtil;
import org.darkforest.dao.mapper.EmployeeMapper;
import org.darkforest.enums.MemberType;
import org.darkforest.model.Employee;
import org.darkforest.ucenter.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * Created by valentina on 15/6/20.
 */
@Service
public class EmployeeServiceImpl implements EmployeeService{

    @Autowired
    private EmployeeMapper employeeMapper;

    @Autowired
    @Qualifier("memberServiceImpl")
    private MemberService memberService;

    /**
     * 设置现有用户为员工，更新member表的member_type字段；增加employee表数据 TODO 配置事务
     * @param employee
     * @return
     */
    @Override
    public int updateMemberToEmploy(Employee employee) {
        employee.setEmpAddtime(DateUtil.unixTimeStampInt().intValue());
        memberService.updateMemberType(employee.getEmpMemberid(), MemberType.EMPLOYEE);
        return employeeMapper.insert(employee);
    }

}
